package com.yunhe.merchants.task;

import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.exception.ModelNotFoundException;
import com.yunhe.common.exception.ObjectNotFoundException;
import com.yunhe.merchants.service.ISuccessProjectService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: DongWenYu
 * @Date: 2021/5/12 15:11
 */
@RestController
@EnableScheduling
public class LeaveScheduled {

    private static final Logger logger = LoggerFactory.getLogger(LeaveScheduled.class);

    @Autowired
    ISuccessProjectService successProjectService;

    /**
     * 每天执行判断成功项目是否即将离场，以及离场
     * @return void 
     * @create 2021/5/12 15:27
     */
    @Scheduled(cron = "0 0 0 0/1 *  ?")
    @RequestMapping(value = "/handle",method = RequestMethod.POST)
    public void handle() throws ArgumentErrorException, ModelNotFoundException {
        //一个月内要离场的更新为即将离场
        successProjectService.leaveInMonth();
        //已经离场
        successProjectService.leave();
    }
}
